#include <iostream>
using namespace std;
#include <unistd.h>

#include "Scanner.h"
#include "Parser.h"
#include "codegen.h"

#define EON_ID "$Id$"
#define VERSION "1.0"

void    Usage();
void    Version();

CodeGenerator * compiler = new CodeGenerator();

int main(int argc, char * argv[])
{
    int c;
    char * ofile, *ifile;
    bool verbose = false;
    extern char *optarg;
    extern int optind, optopt;

    while ((c = getopt(argc, argv, "hvVo:")) != -1)
    {
        switch(c) {
        case 'h':
            Usage();
            exit(0);
        case 'v':
            Version();
            exit(0);
        case 'V':
            verbose = true;
            break;
        case 'o':
            ofile = optarg;
            break;
//        case 'f':
//            ifile = optarg;
//            break;
        case ':':
            cout << "That option requires an argument" << endl;
            exit(1);
        case '?':
            cout << "Unrecognized option: " << optopt << endl;
            exit(1);
        }
    }

    for ( ;optind < argc; optind++)
        if (access(argv[optind],R_OK))
            ifile = argv[optind];

    cout << "Opening " << ifile << endl;

    Scanner     lex(L"test.eon");
    Parser      parser(&lex);

    //compiler = new CodeGenerator();

    return 0;

}

void Usage()
{
    Version();
    cout << "Usage: eoncc [-hvV] [-o output] <source>" << endl;
    cout << "Where: -h         This help message." << endl;
    cout << "       -V         Verbose on" << endl;
    cout << "       -v         Show version." << endl;
    cout << "       -o <file>  Output compiled code to <file>" << endl;
    cout << "        <source>  The EON source file" << endl;
    cout << "Ex: eoncc -o test test.eon" << endl;

}


void Version()
{
    cout << "Extended Online Network Compiler v" << VERSION << endl;
    cout << "Copyright 2010 B. Gian James" << endl;
    cout << EON_ID << endl;

}

